import { Key } from 'react'
import { $get, $put } from '@js/request'
import { CaseSchema } from '@src/components/schema/caseSchema'
import { ConditionSchema } from '@src/components/schema/condition'
import { PerformanceSchema } from '@src/components/schema/performanceSchema'

export async function getCaseListRequest (d: { condition: ConditionSchema[], page: number, limit: number }): Promise<{ list: CaseSchema[], total: number }> {
  const res = await $get('/api/commission/case', {
    condition: JSON.stringify(d.condition),
    page: d.page,
    limit: d.limit
  })
  const list: CaseSchema[] = res.data.list
  list.forEach((li, i) => {
    li.orderno = (d.page - 1) * d.limit + i + 1
  })
  return res.data
}

// 获取绩效考核详情
export async function getPerformanceRequest (id: string): Promise<PerformanceSchema> {
  const res = await $get(`/api/commission/performance/${id}`)
  return res.data
}

// 案件导入请求
export async function caseInputRequest (performanceid: string, caseids: Key[], type: string): Promise<void> {
  const data: { [k: string]: any } = {
    performanceid,
    caseids,
    [type]: 1
  }
  const res = await $put('/api/commission/performance_case/save_list', data)
  return res.data
}
